#include "stm32f10x.h"                  // Device header

int num;

void COUNT_init()
{
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
	
	GPIO_InitTypeDef COUNT_init;
	COUNT_init.GPIO_Mode=GPIO_Mode_IPU;
	COUNT_init.GPIO_Pin=GPIO_Pin_14;
	COUNT_init.GPIO_Speed=GPIO_Speed_50MHz;
	GPIO_Init(GPIOB,&COUNT_init);
	
	GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource14);
	
	EXTI_InitTypeDef EXTI_COUNT_init;
	EXTI_COUNT_init.EXTI_Line=EXTI_Line14;
	EXTI_COUNT_init.EXTI_LineCmd=ENABLE;
	EXTI_COUNT_init.EXTI_Mode=EXTI_Mode_Interrupt;
	EXTI_COUNT_init.EXTI_Trigger=EXTI_Trigger_Falling;
	
	EXTI_Init(&EXTI_COUNT_init);
	
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	NVIC_InitTypeDef NVIC_COUNT_init;
	NVIC_COUNT_init.NVIC_IRQChannel=EXTI15_10_IRQn;
	NVIC_COUNT_init.NVIC_IRQChannelCmd=ENABLE;
	NVIC_COUNT_init.NVIC_IRQChannelPreemptionPriority=1;
	NVIC_COUNT_init.NVIC_IRQChannelSubPriority=1;
	
	NVIC_Init(&NVIC_COUNT_init);
	
}


	
void EXTI15_10_IRQHandler(void)
{
	if(EXTI_GetFlagStatus(EXTI_Line14)==SET)
		num++;
	
	EXTI_ClearITPendingBit(EXTI_Line14);
}
